local skel = fk.CreateSkill{
  name = "tea__tizheng",
  attached_skill_name = "tea__tizheng_active&"
}
Fk:loadTranslationTable{
  ["tea__tizheng"] = "替政",
  [":tea__tizheng"] = "其他角色视为拥有目标仅为你的“放权”。每轮限一次，其他角色的出牌阶段开始时，你可以弃置三张类型不同的牌令其发动“放权”，然后其获得这些牌。",
  -- [":tea__tizheng"] = "其他角色视为拥有目标仅为你的“放权”。每轮限一次，其他角色的出牌阶段开始时，你可以弃置三张类型不同的牌令其发动“放权”，然后其获得这些牌并跳过本回合的弃牌阶段。",
  ["#tea__tizheng_select-invoke"] = "替政：你可以弃置三张类型不同的牌，令 %src 对你发动“放权”",
  ["#tizheng_obtain"] = "获得 %src 弃置的牌",
  ["#tizheng_invalidate"] = "令 %src 的“替政”本轮失效",
}
---get the voice index
---@param player ServerPlayer
---@param tab integer[]
---@return integer
local getVoice = function (player, tab)
  local isZhaozhong = (player.room:getBanner("RoundCount") or 1) % 2 + 1
  return tab[isZhaozhong]
end
---@type TrigSkelSpec<PhaseFunc>
local tea__tezheng = {
  mute = true,
  can_trigger = function (self, event, target, player, data)
    return player:hasSkill(self) and player ~= target and target.phase == Player.Play and #player:getCardIds("he") > 2 and player:usedSkillTimes(skel.name, Player.HistoryRound) == 0
  end,
  on_cost = function (self, event, target, player, data)
    local suc, ret = player.room:askToUseActiveSkill(player, {
      skill_name = "tea__tizheng_select",
      prompt = "#tea__tizheng_select-invoke:" .. target.id
    })
    if suc and ret then
      event:setCostData(self, { cards = ret.cards })
      return true
    end
  end,
  on_use = function (self, event, target, player, data)
    local room = player.room
    room:notifySkillInvoked(player, skel.name, "control")
    player:broadcastSkillInvoke(skel.name, getVoice(player, { 1, 2 }))
    room:throwCard(event:getCostData(self).cards, skel.name, player, player)
    if not player.dead and not target.dead then
      local cids = table.filter(event:getCostData(self).cards, function (id)
        return room:getCardArea(id) == Card.DiscardPile
      end)
      if #cids > 0 then
        room:obtainCard(target, cids, true, fk.ReasonJustMove, target, skel.name)
      end
      room:setPlayerMark(target, "#tea__tizheng-turn", 1)
      if not player.dead then
        target:setSkillUseHistory(skel.attached_skill_name, 1, Player.HistoryTurn)
        -- local useHis = target.skillUsedHistory
        -- local scopes = {Player.HistoryPhase, Player.HistoryTurn, Player.HistoryRound, Player.HistoryGame}
        -- if not useHis[skel.attached_skill_name] then
        --   useHis[skel.attached_skill_name] = {}
        -- end
        -- if not useHis[skel.attached_skill_name][Player.HistoryTurn] then
        --   for _, s in ipairs(scopes) do
        --     useHis[skel.attached_skill_name][s] = 1
        --   end
        -- end
        target:endCurrentPhase()
      end
    end
  end
}
---@diagnostic disable-next-line: undefined-field
skel:addAcquireEffect(function (self, player)
  local room = player.room
  for _, p in ipairs(room:getOtherPlayers(player, false)) do
    room:handleAddLoseSkills(p, skel.attached_skill_name, nil, false, true)
  end
end)
---@type TrigSkelSpec<TrigFunc>
local tea__tizheng_re = {
  can_refresh = function(self, event, target, player, data)
    return target == player
  end,
  on_refresh = function(self, event, target, player, data)
    local room = player.room
    if table.find(room.alive_players, function (p)
      return p ~= player and p:hasSkill(skel.name, true)
    end) then
      room:handleAddLoseSkills(player, skel.attached_skill_name, nil, false, true)
    else
      room:handleAddLoseSkills(player, "-" .. skel.attached_skill_name, nil, false, true)
    end
  end,
}
---@type TrigSkelSpec<EventPhaseChangingFunc>
local tea__tizheng_trig = {
  can_refresh = function (self, event, target, player, data)
    return target == player and player:getMark("#tea__tizheng-turn") == 1 and data.phase == Player.Discard
  end,
  on_refresh = function (self, event, target, player, data)
    data.skipped = true
  end
}
skel:addEffect(fk.EventPhaseStart, tea__tezheng)
skel:addEffect(fk.AfterPropertyChange, tea__tizheng_re)
-- skel:addEffect(fk.EventPhaseChanging, tea__tizheng_trig)

return skel